package com.ry.est.controller;

import com.ry.est.dto.CommonResult;
import com.ry.est.dto.ModelDTO;
import com.ry.est.dto.ModelDetailDTO;
import com.ry.est.dto.PageResult;
import com.ry.est.entity.Model;
import com.ry.est.service.ModelService;
import com.ry.est.util.ResultUtil;
import org.omg.CORBA.OMGVMCID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ModelController {
    @Autowired
    private ModelService modelService;

    @GetMapping("/api/model/search")
    public CommonResult<PageResult<ModelDTO>> search(Model model,
                                                     @RequestParam(defaultValue = "1") Integer pageNo,
                                                     @RequestParam(defaultValue = "20") Integer pageSize){
        PageResult<ModelDTO> pageResult = modelService.listByPage(model, pageNo, pageSize);

        return ResultUtil.success(pageResult);
    }

    @GetMapping("/api/model/{id}/detail")
    public CommonResult<ModelDetailDTO> detail(@PathVariable("id") Long id){
        ModelDetailDTO modelDetailDTO = modelService.getById(id);


        return ResultUtil.success(modelDetailDTO);
    }
}
